
 ************************************************************************************
 
/*
--------------------------------------------------------------------------------------------------------
The following code is to replicate all results in Tables 1- 3 in Rodrigue et al. (2020)
--------------------------------------------------------------------------------------------------------
The meanings of each variable:

1. lnso2: firm-level emission intensity of so2;
2. lndust: firm-level emission intensity of industrial dust;
3. Abatement_so2: firm-level abatement in so2;
4. Abatement_dust: firm-level abatement in dust;
5. lnKL: firm-level capital to labor ratio
6. Tariff: tariff
7. lnso2_ini: initial level of so2 emission intensity;
8. lndust_ini: initial level of dust emission intensity;
9. tariff_prod: initial tariff* initial-producivity
10. ventilation: ventilation coefficients for each province in each year;
11. ventilation_prod: ventilation coefficient * initial productivity
12. cic: 4-digit industry classification 
13. prov: province
14. ownership: SOE (ownerships==1|ownerships==2); private (ownerships==3); foreign (ownerships==4|ownerships==5);
15. cic_year, prov_year, owner_year: industry-year, province-year and ownership-year dummies. 
*/


 
 ***************************        **********************************************************
 ***************************Table 1 ************************************************************
  **************************        **********************************************************
*-------------------------------------***************************
*1.  The followig code generate table 1 (OLS results)
*-------------------------------------------------------------------------
use "D:\Nanjing\2019\pollution2\submission\files for submission\data\tables_comp",clear
rename exp_dummy2 Export
rename so2_new1 Abatement_so2
rename dust_new1 Abatement_dust
rename tfp_acf_new Productivity
rename lntariff Tariff
rename lnkl_lag lnKL
rename treatment_tfp tariff_prod
rename treatment_so2 ventilation_prod



*------------------------------------------
* 1.1 So2: Columns 1 and 2 in  Table 1 
*------------------------------------------
reghdfe lnso2  Export Abatement_so2  Productivity Tariff  , a(cic prov year ownership) cluster (prov_c)
est sto so2_OLS1

reghdfe lnso2  Export Abatement_so2  Productivity Tariff   lnKL lnso2_ini, a(cic prov year ownership) cluster (prov_c)
est sto so2_OLS2

*-------------------------------------------
*1.2 dust: Columns 5 and 6 of Table 1 
*---------------------------------------------
reghdfe lndust  Export Abatement_dust  Productivity Tariff , a(cic prov year ownership) cluster (prov_c)
est sto dust_OLS1

reghdfe lndust  Export Abatement_dust   Productivity Tariff lnKL lndust_ini, a(cic prov year ownership) cluster (prov_c) 
est sto dust_OLS2


***********************************************************************************************************
*-------------------------------------------------------------------------
use "D:\Nanjing\2019\pollution2\submission\files for submission\data\tables_comp2",clear


rename exp_dummy2 Export
rename so2_new1 Abatement_so2
rename dust_new1 Abatement_dust
rename tfp_acf_new Productivity
rename lntariff Tariff
rename lnkl_lag lnKL
rename treatment_tfp tariff_prod
rename treatment_so2 ventilation_prod


 capture drop ub
 egen ub=pctile(lndust),p(97)
 
 
 
*--------------------------------------------------------------------
* 1.3 column 3 and 7 of Table 1
*-----------------------------------------------------------------
 reghdfe lnso2  Export Abatement_so2 Productivity Tariff lnKL , a(indc year) cluster (prov_c)
 

 reghdfe lndust  Export Abatement_dust   Productivity Tariff lnKL if lndust<ub, a(indc  year) cluster (prov_c)

 
use "D:\Nanjing\2019\pollution2\submission\files for submission\data\tables_comp2",clear
rename exp_dummy_d Export
rename so2_new1_d Abatement_so2
rename dust_new1_d Abatement_dust
rename tfp_acf_new_d Productivity
rename lntariff_d Tariff
rename lnkl_d lnKL
rename treatment_tfp tariff_prod
rename treatment_so2 ventilation_prod

capture drop ub_dust
egen ub_so2=pctile(lnso2), p(97)
egen ub_dust=pctile(lndust),p(97)

*-----------------------------------------------------------------------------------------------------------------
*1.4: column 4 and 8 of Table 1
*-----------------------------------------------------------------------------------------------------------------
reghdfe lnso2_d  Export Abatement_so2   Productivity Tariff lnKL , a(cic prov year ownership ) cluster (prov_c)

reghdfe lndust_d  Export Abatement_dust  Productivity Tariff lnKL , a(cic prov year ownership )  cluster (prov_c)
***********************************************************************************************************************







*******************************************************************************************

*-------------------------------------             -------------------------------------------
*-------------------------------------Table 2 and 3------------------------------------------
*-------------------------------------             -------------------------------------------


 
 
 
*-----------------------------------------------------------
*2.  The followig code generate table 2 and 3 (IV results)
*-------------------------------------------------------------------------

use "D:\Nanjing\2019\pollution2\submission\files for submission\data\tables_comp",clear
rename exp_dummy2 Export
rename so2_new1 Abatement_so2
rename dust_new1 Abatement_dust
rename tfp_acf_new Productivity
rename lntariff Tariff
rename lnkl_lag lnKL
rename treatment_tfp tariff_prod
rename treatment_so2 ventilation_prod




*-------------------------------------------------------------
*2.1 So2: Columns 1 and 2 of Table 3 (first stage in Table 2)
*--------------------------------------------------------------
ivreghdfe lnso2  (Export Abatement_so2= ventilation ventilation_prod tariff_prod   )   Productivity Tariff,   a(cic prov year ownership) cluster (prov_c) first


ivreghdfe lnso2  (Export Abatement_so2= ventilation ventilation_prod tariff_prod)   Productivity Tariff lnKL lnso2_ini,   a(cic prov year ownership) cluster (prov_c) first

/*
* compute R2
predict y_hat, xb
egen y_bar=mean(lndust)

gen diff1=(y_hat-y_bar)^2
egen SSR=sum(diff1)

gen diff2=(lndust-y_bar)^2
egen SST=sum(diff2)

gen R2=SSR/SST 
sum R2
*/

*-------------------------------------------------------------
*2.2 dust: Columns 5 and 6 of Table 3 (frist stage in Table 2)

*-------------------------------------------------------------

ivreghdfe lndust  (Export Abatement_dust=  ventilation ventilation_prod tariff_prod)   Productivity Tariff  , a(cic prov year ownership) cluster (prov_c) first


ivreghdfe lndust  (Export Abatement_dust=  ventilation ventilation_prod tariff_prod)   Productivity Tariff  lnKL lndust_ini, a(cic prov year ownership) cluster (prov_c) first


 
 *-------------------------------------------------------------------------------------------------------------------------
 

 
use "D:\Nanjing\2019\pollution2\submission\files for submission\data\tables_comp2",clear
rename exp_dummy2 Export
rename so2_new1 Abatement_so2
rename dust_new1 Abatement_dust
rename tfp_acf_new Productivity
rename lntariff Tariff
rename lnkl_lag lnKL
rename treatment_tfp tariff_prod
rename treatment_so2 ventilation_prod


 capture drop ub
 egen ub=pctile(lndust),p(97)
 

*-------------------------------------------------------------
* 2.3 Columns 3 and 7 of Table 3 (first stage in Table 2)
*-------------------------------------------------------------

*egen prov_d=group(party_id year cic indc)
 
 ivreghdfe lnso2  (Export Abatement_so2= ventilation ventilation_prod tariff_prod)  Productivity Tariff lnKL  , a(indc year) cluster(prov_c) first

 
 ivreghdfe lndust  (Export Abatement_dust= ventilation ventilation_prod tariff_prod)  Productivity Tariff lnKL if lndust<ub,  a(indc  year) cluster(prov_c) first


 
/*
* compute R2
predict y_hat, xb
egen y_bar=mean(lndust_d)

gen diff1=(y_hat-y_bar)^2
egen SSR=sum(diff1)

gen diff2=(lndust_d-y_bar)^2
egen SST=sum(diff2)

gen R2=SSR/SST 
sum R2
*/
 

drop Productivity Tariff lnKL Abatement_so2 Abatement_dust Export
 
rename so2_new1_d Abatement_so2
rename dust_new1_d Abatement_dust
rename exp_dummy_d Export
rename tfp_acf_new_d Productivity
rename lntariff_d Tariff
rename lnkl_d lnKL

*-------------------------------------------------------------
* 2.4 Columns 4 and 8 of Table 3 (first stage in Table 2)
*-------------------------------------------------------------
ivreghdfe lnso2_d  (Export Abatement_so2=  ventilation ventilation_prod tariff_prod)   Productivity Tariff lnKL , a(cic prov year ownership) cluster(prov_c) first


ivreghdfe lndust_d  (Export Abatement_dust= ventilation ventilation_prod tariff_prod)  Productivity Tariff lnKL , a(cic prov year ownership) cluster(prov_c) first
***************************************************************************************************************************


 
 
 